package liquidfs.data.fs;

public abstract class AbstractLiquidObject implements LiquidObject, Comparable<LiquidObject> {

   @Override
   public int hashCode () {
      return this.getPath().hashCode();
   }
   
   @Override
   public boolean equals (Object object) {
      if (object instanceof LiquidObject) {
         LiquidObject lo = (LiquidObject) object;
         return this.getPath().equals(lo.getPath());
      }
      else {
         return false;
      }
   }

   @Override
   public int compareTo(LiquidObject object) {
      return this.getPath().compareTo(object.getPath());
   }
   
   @Override
   public String toString () {
      return this.getPath();
   }
   
   @Override
   public String getParentPath () {
      
      String path = this.getPath();
      
      if (path.equals("/"))
         return null;
      
      return path.substring(0, path.lastIndexOf('/'));
   }
}
